<?php

namespace app\common\validate\xilujob;

use app\common\model\xilujob\CompanyScale;
use app\common\model\xilujob\CompanyProperties;
use app\common\model\xilujob\IndustryCategory;
use think\Validate;

class EnterpriseInfo extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'full_name|公司全称' => ['length:0,50'],
        'industry_category_id|所属行业' => ['industry_valid'],
        'contact_person|联系人' => ['length:0,20'],
        'contact_phone|联系电话' => ['length:0,20'],
        'address|公司地址' => ['length:0,50'],
        'company_scale_id|公司规模' => ['scale_valid'],
        'company_type_id|企业类型' => ['company_type_valid'],
        'intro|公司简介' => ['length:0,500'],
    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];

    protected function industry_valid($value, $rule, $data) {
        if($value==0)
            return true;
        return IndustryCategory::where('id',$value)->count() > 0 ? true: '所属行业选择错误';
    }

    protected function scale_valid($value, $rule, $data) {
        if($value==0)
            return true;
        return CompanyScale::where('id',$value)->count() > 0 ? true: '公司规模选择错误';
    }

    protected function company_type_valid($value, $rule, $data) {
        if($value==0)
            return true;
        return CompanyProperties::where('id',$value)->count() > 0 ? true: '企业类型选择错误';
    }
    
}
